/**
 * 自定义hooks：useTimeout
 */

import useTimeout from "@/hooks/useTimeout";
import { Button } from "antd";
import React, { useState } from "react";

interface NameState {
  name: string;
}
const UseTimeOut: React.FC = () => {
  const [nameObj, setNameObj] = useState<NameState>({ name: "小学" });
  const [count, setCount] = useState<number>(0);

  /* useTimeout(() => {
    console.log(nameObj);
  }, 1000); */

  useTimeout(() => {
    console.log(count);
  }, 2000);

  const handleClick = () => {
    setNameObj(prevState => {
      const nowState = Object.assign(prevState, { name: "xax" });
      console.log(nowState === prevState);
      return nowState;
    });
  };

  console.log(nameObj.name);

  return (
    <>
      <h3>计数器:{count}</h3>
      <Button onClick={() => setCount(count => count + 1)}>click count</Button>
      <h3>姓名:{nameObj.name}</h3>
      <Button type="ghost" onClick={handleClick}>
        click Name
      </Button>
    </>
  );
};
export default UseTimeOut;
